import asyncio
import time

from utils.handler import AsyncHandler, MethodHandler
from utils.log import Log


class MyClass(Log):
    @MethodHandler(end=True)
    def f(self, s):
        time.sleep(s)
        self.info('f done')
        return 42

    @AsyncHandler(end=True)
    async def g(self):
        # self.f(0.1)
        await self.g1()
        self.info('g done')
        return 1
        # self.error(33, "test error")

    @AsyncHandler(end=True)
    async def g1(self):
        self.info('g1 done')
        return 1


async def main():
    my_class = MyClass()
    # print(isinstance(my_class, Log))
    loop = asyncio.get_event_loop()

    return await asyncio.gather(
        loop.run_in_executor(None, my_class.f, 3),
        loop.run_in_executor(None, my_class.f, 3),
        loop.run_in_executor(None, my_class.f, 3),
        loop.run_in_executor(None, my_class.f, 3),
        # my_class.f(5),
        # my_class.f(5),
        # my_class.f(5),
        # my_class.f(5),
        my_class.g())


if __name__ == '__main__':
    asyncio.run(main())
